package com.duqc.springbatch;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.item.ItemReader;
import org.springframework.stereotype.Component;

/**
 * @ClassName JobListener
 * @Description JobListener
 * @Author duqc
 * @Date 2022/7/18
 **/
@Slf4j
@Component
public class JobListener implements JobExecutionListener {

    private Long startTime;

    @Override
    public void beforeJob(JobExecution jobExecution) {
        startTime = System.currentTimeMillis();
        log.info("job before " + jobExecution.getJobParameters());
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        log.info("JOB STATUS : {}", jobExecution.getStatus());
        log.info("Job Cost Time : {}/ms", System.currentTimeMillis() - startTime);
    }
}
